<?
/**
 * 用户模块处理类
 * 
 * @copyright Copyright (c) 2008 sdmblog (http://www.sdmblog.cn)
 * @author sdomain(sdomain@live.cn)
 * @version user.class.php Sat May 17 17:05:36 CST 2008 php $
 */
include_once('../include/common.inc.php');
include_once('../model/user.model.php');
require_once ('../xajax/inc/xajax.inc.php');
$xajax = new xajax('user.class.php');
$xajax->registerFunction('userRegSave');
session_start();

function userRegSave($regInfo)
{
	$obj = new xajaxResponse();
	$auth_num = $_SESSION['auth_num'];
	//$post = implode(',',$regInfo);
	if ($regInfo['authnum']!=$auth_num) {
		$obj->alert('验证码出错，请输入正确的验证码');
		$obj->assign('submit','value',' 提交 ');
		$obj->assign('submit','disabled',false);
		return $obj;
	}
	
	if (!isUserName($regInfo['username'],4,14)) {
		$obj->alert('用户名非法');
		$obj->assign('submit','value',' 提交 ');
		$obj->assign('submit','disabled',false);
		return $obj;
	}
	if ($regInfo['password']!=$regInfo['repassword']){
		$obj->alert('两次密码不一至');
		$obj->assign('submit','value',' 提交 ');
		$obj->assign('submit','disabled',false);
		return $obj;
	}elseif (strlen($regInfo['password'])>16 || strlen($regInfo['password'])<6){
		$obj->alert('密码长度不符：6-16');
		$obj->assign('submit','value',' 提交 ');
		$obj->assign('submit','disabled',false);
		return $obj;
	}
	if (!empty($regInfo['email']) && !isEmail($regInfo['email'])) {
		$obj->alert('邮件地址不正确，请输入正确的邮件地址');
		$obj->assign('submit','value',' 提交 ');
		$obj->assign('submit','disabled',false);
		return $obj;
	}
	$homepage = $regInfo['homepage'];
	$homepage = str_replace('\'','\\\'',$homepage);
	$homepage = str_replace(' ','',$homepage);
	$regInfo['homepage'] = $homepage;
	
	try {
		$user = new model_user();
		$user->addUser($regInfo);
		$obj->alert('注册成功');
		global $virdir;
		$obj->redirect('/'.$virdir.'index.php');
	}catch (Exception $e){
		$obj->alert($e->getMessage());
		$obj->assign('submit','value',' 提交 ');
		$obj->assign('submit','disabled',false);	
	}
	return $obj;
}
$xajax->processRequest();
?>